package com.tiancheng.trade.payment.channel;

import com.tiancheng.trade.commom.core.exception.BusinessException;
import com.tiancheng.trade.commom.core.exception.error.BusinessErrorInfoEnum;
import com.tiancheng.trade.commom.core.utils.ServiceLocator;
import com.tiancheng.trade.payment.channel.apple.ApplePayChannel;
import com.tiancheng.trade.payment.channel.cmb.CmbPayChannel;
import com.tiancheng.trade.payment.channel.fudian.FudianPayChannel;
import com.tiancheng.trade.payment.channel.gaocheng.GaoChengChannel;
import com.tiancheng.trade.payment.channel.lkl.LklPayChannel;
import com.tiancheng.trade.payment.channel.ums.UmsPayChannel;
import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.payment.channel.umsdhjt.UmsDhjtPayChannel;
import com.tiancheng.trade.payment.channel.umsmop.UmsMopPayChannel;
import com.tiancheng.trade.payment.channel.umsshop.UmsShopPayChannel;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付渠道工厂
 *
 * @author kellen
 * @date 2024/4/16
 */
public class PayChannelFactory {

    private static Map<String, Class> payChannelMap = new HashMap<>();

    static {
        payChannelMap.put(PaymentChannelEnum.CMB.getCode(), CmbPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.FUDIAN.getCode(), FudianPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.APPLE.getCode(), ApplePayChannel.class);


        payChannelMap.put(PaymentChannelEnum.UMS.getCode(), UmsPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS_DHJT.getCode(), UmsDhjtPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS_MOP.getCode(), UmsMopPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS_SHOP.getCode(), UmsShopPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.gao_cheng_nong_hang.getCode(), GaoChengChannel.class);
        payChannelMap.put(PaymentChannelEnum.lkl_pay.getCode(), LklPayChannel.class);
    }

    /**
     * 获取支付渠道
     * @param channel
     * @return
     * @throws BusinessException
     */
    public static AbstractPayChannel get(String channel) throws BusinessException {
        BusinessErrorInfoEnum.CHANNEL_NO_MATCH.assertIsTrue(payChannelMap.containsKey(channel));
        return (AbstractPayChannel) ServiceLocator.getBean(payChannelMap.get(channel));
    }

    /**
     * 获取苹果支付渠道
     * @return
     */
    public static ApplePayChannel getApplePayChannel(){
        return ServiceLocator.getBean(ApplePayChannel.class);
    }
}
